package com.fahui.vote.domain.vote.factory.create;

import com.fahui.vote.domain.vote.enums.CreateVoteEnum;
import com.fahui.vote.domain.vote.factory.create.CreateVote;
import com.fahui.vote.domain.vote.value.CreateVoteV;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * *
 *
 * @author caiyj *
 * @create 2019-10-27 23:25
 **/
@Component
public class VoteCreateFactory {

    @Resource
    private List<CreateVote> createVotes;

    public Boolean create(CreateVoteV createVoteV, CreateVoteEnum createVoteEnum) {
        Assert.isTrue(CollectionUtils.isEmpty(createVotes), "S_INIT-CREATE-VOTE-FACTORY_ERROR");
        for (CreateVote createVote : createVotes) {
            if (createVote.getCreateVoteEnum().equals(createVoteEnum)) {
                createVote.create(createVoteV);
            }
        }
        return Boolean.TRUE;
    }
} 